import request from '@/utils/request'

/**
 * 获取流程列表
 * @param query
 */
export function queryProcess(query) {
  if (!query) {
    query = {};
  }
  return request({
    url: '/process/page',
    method: 'post',
    data: query
  })
}

/**
 * 删除已部署的流程
 * @param deployId
 */
export function deleteProcess(deployId) {
  return request({
    url: '/process/delete',
    method: 'post',
    params: {
      deploymentId: deployId
    }
  })
}

/**
 * 流程挂起或激活
 * @param id
 * @param operation
 */
export function updateSuspendState(id, operation) {
  return request({
    url: `/process/update/${operation}/${id}`,
    method: 'get',
  })
}

/**
 * 流程转模型
 * @param id
 */
export function convertToModel(id) {
  return request({
    url: `/process/convert2Model/${id}`,
    method: 'get',
  })
}

/**
 * 加载流程节点信息
 * @param id
 */
export function loadNode(id) {
  return request({
    url: `/process/nodes/${id}`,
    method: 'get',
  })
}

/**
 * 保存节点审批人员配置信息
 * @param data
 */
export function saveTaskApproverSetting(data) {
  return request({
    url: '/process/node/approver/save',
    method: 'post',
    data: data
  })
}

/**
 * 加载节点审批人员配置信息
 * @param query
 */
export function loadTaskApproverSetting(query) {
  return request({
    url: '/process/node/approver',
    method: 'post',
    data: query
  })
}

/**
 * 保存流程扩展信息
 * @param data
 */
export function saveProcessExtendInfo(data) {
  return request({
    url: '/process/extend/save',
    method: 'post',
    data: data
  })
}

/**
 * 查询流程扩展信息
 * @param key
 */
export function searchProcessExtendInfo(key) {
  return request({
    url: `/process/extend/search/${key}`,
    method: 'get',
  })
}

/**
 * 发起流程
 * @param data
 */
export function startProcess(data) {
  return request({
    url: '/api/process/start',
    method: 'post',
    data: data
  })
}
